Skip to content

feat: Highlight and prioritize code definitions in grep results#299

Open
yashksaini-coder wants to merge 8 commits intodmtrKovalenko:mainfrom
yashksaini-coder:feat/context-definition-detection
Open

feat: Highlight and prioritize code definitions in grep results#299
yashksaini-coder wants to merge 8 commits intodmtrKovalenko:mainfrom
yashksaini-coder:feat/context-definition-detection

Conversation

@yashksaini-coder
Copy link
Copy Markdown

Fixes:- #297

This PR adds definition detection to the grep engine.

  • Prioritization: Definitions are now stably sorted to the top of the results.
  • Visuals: Added a [def] indicator highlighted with combo_header to make symbols pop.
  • Config: New classify_definitions toggle added to grep settings (default false).

Kept it focused on definitions only for now to avoid messing with the UI for context lines.

@dmtrKovalenko

Copy link
Copy Markdown
Owner

@dmtrKovalenko dmtrKovalenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution but I think we can make it even better

Comment thread crates/fff-core/src/grep.rs Outdated
Comment thread lua/fff/grep/grep_renderer.lua Outdated
Comment thread lua/fff/grep/grep_renderer.lua Outdated
@yashksaini-coder yashksaini-coder force-pushed the feat/context-definition-detection branch 3 times, most recently from 1606258 to 5f722dc Compare March 19, 2026 12:14
@yashksaini-coder yashksaini-coder force-pushed the feat/context-definition-detection branch from f87e12d to 43331dc Compare March 20, 2026 08:29
@yashksaini-coder
Copy link
Copy Markdown
Author

@dmtrKovalenko can we run the CI/CD checks. I've updated the branch to latest commit

@dmtrKovalenko
Copy link
Copy Markdown
Owner

Thank you. If you don’t mind I’ll push to your PR with some changes I’d like to tune how this feature feels

@yashksaini-coder
Copy link
Copy Markdown
Author

yashksaini-coder commented Mar 21, 2026

Thank you. If you don’t mind I’ll push to your PR with some changes I’d like to tune how this feature feels

Sure why not works for me @dmtrKovalenko Would like to see your approach as well for improving the highlighting in grep

@yashksaini-coder
Copy link
Copy Markdown
Author

Hi @dmtrKovalenko follownig up on my PR, have you made any changes ? also I see some skipped workflows are they manual based for maintainers or reviewers

Copilot AI review requested due to automatic review settings April 7, 2026 08:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR exposes the core grep engine’s definition-classification signal to Neovim and uses it to visually mark definition matches and optionally prioritize them in results, controlled via a new grep.classify_definitions config toggle.

Changes:

  • Added grep.classify_definitions (default false) and threaded it through the Lua → Rust FFI → core grep options.
  • Exposed is_definition on each grep match item to Lua and rendered a [def] indicator in the grep UI.
  • When enabled, core grep post-processes results to prioritize definition matches.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lua/fff/grep/init.lua Passes classify_definitions through to the Rust live_grep FFI call.
lua/fff/grep/grep_renderer.lua Adds virtual-text [def] marker for definition matches.
lua/fff/conf.lua Adds grep.classify_definitions to config typing + defaults.
crates/fff-nvim/src/lua_types.rs Includes is_definition in Lua grep match items.
crates/fff-nvim/src/lib.rs Adds classify_definitions as a new optional live_grep parameter and forwards into GrepSearchOptions.
crates/fff-core/src/grep.rs Sorts matches to prioritize definitions when classification is enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/fff-core/src/grep.rs Outdated
Comment thread crates/fff-core/src/grep.rs Outdated
Comment thread lua/fff/grep/grep_renderer.lua Outdated
@yashksaini-coder
Copy link
Copy Markdown
Author

@dmtrKovalenko I have addressed the concerns and issues raised by copilot review, looking forward to your review and feedback, Thanks

@dmtrKovalenko
Copy link
Copy Markdown
Owner

I am sorry brother, I have been working on some additional changes because I really want this feature to shine and jumped away to the random markerting PRs

i will revisit, push some changes and merge this PR in a few days

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

crates/fff-nvim/src/lib.rs:295

  • live_grep’s destructured argument tuple includes trim_whitespace, but the tuple type annotation below only has 9 elements (ending at Option<bool> for classify_definitions). This will not compile; update the tuple type to include an additional Option<bool> for trim_whitespace (and keep the order aligned with the Lua call).
        classify_definitions,
        trim_whitespace,
    ): (
        String,
        Option<usize>,
        Option<usize>,
        Option<u64>,
        Option<usize>,
        Option<bool>,
        Option<String>,
        Option<u64>,
        Option<bool>,
    ),

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lua/fff/grep/init.lua Outdated
Comment thread crates/fff-core/src/grep.rs
Comment on lines +2435 to +2439
// All matches for a given file must be contiguous (no interleaving).
if !result_defs.matches.is_empty() {
let mut last_file = result_defs.matches[0].file_index;
let mut seen_files = std::collections::HashSet::new();
seen_files.insert(last_file);
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new test asserts ordering invariants but doesn’t assert that the result set actually contains at least one is_definition == true match (and at least one non-definition) to make the assertions meaningful. If definition classification regresses to always-false, this test can still pass vacuously; consider adding explicit assertions about the presence of both kinds of matches in result_defs.matches.

Copilot uses AI. Check for mistakes.
yashksaini-coder and others added 2 commits April 23, 2026 19:26
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants